// pages/refund/refund.js
const app = getApp()
var api = require('../../../utils/api.js')
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num: 1,
    goods: [],
    showRegulations: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var oid = options.oid;
    var op_id = options.op_id;
    this.setData({
      oid: oid,
      op_id: op_id
    })
  },

  onShow: function() {
    this.orderDetails();
  },
  orderDetails: function() {
    var that = this;
    var oid = this.data.oid;
    var op_id = this.data.op_id;
    api.POST({
      params: {
        "order_id": oid,
        'op_id': op_id
      },
      url: app.globalData.base_url + 'aftersale/getGoodsInfo',
      success: function(res) {
        if (util.isEmpty(res.data.code)) {
          var productDetails = res.data.data;
          var total = (productDetails.number * productDetails.price).toFixed(2);
          var returnPrice = (productDetails.price * that.data.num).toFixed(2);
          that.setData({
            productDetails: productDetails,
            total: total,
            returnPrice: returnPrice
          })
        }
      }
    })
  },
  refundLink: function(e) {
    var type = e.currentTarget.dataset.type
    var oid = this.data.oid;
    var op_id = this.data.op_id;
    wx.redirectTo({
      url: '/center/pages/refund/refund?oid=' + oid + "&op_id=" + op_id + "&type=" + type
    })
  },

  // 使用规则弹框
  showRegulations: function() {
    this.setData({
      showRegulations: true
    })
  },
  // 使用规则弹框隐藏
  hiddenRegulations: function() {
    this.setData({
      showRegulations: false
    })
  },

})